<?php
/**
 * Yotaku Shop - yshop
 * @author Creatint<creatint@163.com>
 * @copyright www.yotaku.cn 2016
 */
namespace Admin\Controller;
/**
 * 后台 图片处理控制器 继承AdminController
 * Class PictureController
 * @package Admin\Controller
 */
class PictureController extends AdminController {
    public function index(){
        $this->display();
    }
    public function upload(){
        $return = array('status'=>0,'info'=>'上传失败');
        if(!IS_POST){
            $this->ajaxReturn($return);
        }

        /* 调用文件上传组件上传文件 */
        $Picture    =   D('Picture');
        $pic_driver = C('PICTURE_UPLOAD_DRIVER');
        $info = $Picture->upload(
            $_FILES,
            C('PICTURE_UPLOAD'),
            C('PICTURE_UPLOAD_DRIVER'),
            C("UPLOAD_{$pic_driver}_CONFIG")
        );

        /* 记录图片信息 */
        if($info){
            $return['status'] = 1;
            $return['info'] =   '上传成功';
            $return = array_merge($info['Filedata'], $return);
        } else {
            $return['status'] = 0;
            $return['info']   = $Picture->getError();
        }


        $this->ajaxReturn($return);
    }
}